package org.jeecg.flowable.controller.definition;


import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.flowable.entity.definition.BpmTaskAssignRule;
import org.jeecg.flowable.service.definition.BpmTaskAssignRuleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController
@RequestMapping("/bpm/task-assign-rule")
@Validated
public class BpmTaskAssignRuleController {

    @Resource
    private BpmTaskAssignRuleService taskAssignRuleService;

    @GetMapping("/list")
    @AutoLog(value = "获得任务分配规则列表")
    @ApiOperation(value="获得任务分配规则列表", notes="获得任务分配规则列表")
    public Result<?> getTaskAssignRuleList(
            @RequestParam(value = "modelId", required = false) String modelId,
            @RequestParam(value = "processDefinitionId", required = false) String processDefinitionId) {
        return Result.ok(taskAssignRuleService.getTaskAssignRuleList(modelId, processDefinitionId));
    }

    @PostMapping("/create")
    @AutoLog(value = "创建任务分配规则")
    @ApiOperation(value="创建任务分配规则", notes="创建任务分配规则")
    public Result<?> createTaskAssignRule(@Valid @RequestBody BpmTaskAssignRule reqVO) {
        taskAssignRuleService.save(reqVO);
        return Result.ok(reqVO.getId());
    }

    @PutMapping("/update")
    @AutoLog(value = "更新任务分配规则")
    @ApiOperation(value="更新任务分配规则", notes="更新任务分配规则")
    public Result<?> updateTaskAssignRule(@Valid @RequestBody BpmTaskAssignRule reqVO) {
        taskAssignRuleService.updateById(reqVO);
        return Result.ok(true);
    }
}
